package com.loongtech.bi.manager.player;

import com.loongtech.bi.entity.player.EntityUserTwoStepLoginPercent;
import com.loongtech.core.jpa.manager.ManagerQueryCacheBase;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class UserTwoStepLoginPercentManager extends ManagerQueryCacheBase<EntityUserTwoStepLoginPercent> {
	private static final long serialVersionUID = 1L;
	
	/**
	 * 根据开始结束时间，求有效新增用户数
	 * @param dateStart
	 * @param dateEnd
	 * @return
	 */
	public List<EntityUserTwoStepLoginPercent> getUserTwoStepLoginPercentByDate(Date dateStart, Date dateEnd) {
		return findByQuery("from EntityUserTwoStepLoginPercent  where 1=1 and day>=:dayStart and day<=:dayEnd order by day ", "dayStart", dateStart, "dayEnd", dateEnd);
	}
	
	/**
	 * 根据开始结束时间查询某个维度的数值
	 * @param dateStart
	 * @param dateEnd
	 * @return
	 */
	public List<Object[]> getUserTwoStepLoginPercentByAllKind(Date dateStart, Date dateEnd,String queryPlatform, String queryChannel, String queryServer) {
		return findByQuery("select date_format(day,'%Y-%m-%d'),sum(first_week_three_login_num),sum(second_week_one_login_num),sum(second_week_one_login_num) * 1.0 / sum(first_week_three_login_num) from EntityUserTwoStepLoginPercent where day>=:dayStart and day<=:dayEnd and platformid = '"+queryPlatform+"' and channelid = '"+queryChannel+"' and serverid = '"+queryServer+"' group by day order by day desc", "dayStart", dateStart, "dayEnd", dateEnd);
	}
}
